package lesson8.heartbeat;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.CharsetUtil;

import java.util.concurrent.TimeUnit;

/**
 * <br/>
 * Created on : 2018-01-29 23:12
 * @author lizebin
 */
public class ServerInitializer extends ChannelInitializer<NioSocketChannel> {

	@Override
	protected void initChannel(NioSocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		//空闲检测处理器:1-如果5秒钟服务端没有读操作，则触发这个事件;2-如果5秒钟服务端没有写操作，同上;3-如果5秒钟没有读和写
		pipeline.addLast(new IdleStateHandler(5, 5, 5, TimeUnit.SECONDS));
		pipeline.addLast(new ServerHandler());
	}

}
